package com.jones.restaurant.framework;

import java.util.Map;

import org.apache.http.params.HttpParams;

import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.jones.restaurant.utils.HttpRequestParams;
import com.jones.restaurant.utils.VolleyTool;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;

public class BaseActivity extends FragmentActivity implements IBaseNetInterface{
	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		
	}
	
	public void get(String suffixUrl,Map<String,String> params){
		String prefixUrl = Constants.serverAddress+suffixUrl;
		String fullUrl = HttpRequestParams.getFullUrlParams(prefixUrl, params);
		VolleyTool.getQueueInstace(
				getApplicationContext()).add(
						new StringRequest(fullUrl, 
								new MyResponseListener(fullUrl, suffixUrl), 
								new ErrorListener() {

							@Override
							public void onErrorResponse(VolleyError arg0) {
								// TODO Auto-generated method stub
								
							}
						}));
	}
	
	
	public class MyResponseListener implements Listener{
		private String fullUrl;
		private String suffixUrl;
		
		public MyResponseListener(String fullUrl,String suffixUrl){
			this.fullUrl = fullUrl;
			this.suffixUrl = suffixUrl;
		}
		
		@Override
		public void onResponse(Object arg0) {
			// TODO Auto-generated method stub
			onReceive(fullUrl, suffixUrl, (String)arg0);
		}
		
	}


	@Override
	public void onReceive(String fullUrl, String suffixUrl, String response) {
		Log.i("jones", response);
	}
}
